package com.maxmlr.mybatisplus.common.base.dto;


import com.alibaba.fastjson.annotation.JSONField;
import com.maxmlr.mybatisplus.common.base.cst.CommonCst;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class SimpleRespDTO implements Serializable {

	/** serialVersionUID*/  
	private static final long serialVersionUID = 1L;

	/**
	 * 请求唯一标示
	 */
	@JSONField(serialize=false)
	private String requestId;

	// 第几页
	private Integer pageNum;

	// 每页显示多少行
	private Integer pageSize;

	// 总数
	private Long total;

	// 返回码
	private String returnCode;
	
	private String returnMsg;

	// 返回数据信息，目前有list,totalData
	private Map<String, Object> data;

	// 冗余字段，需要时候用
	@JSONField(serialize = false) // 表示将该对象转换为json String的时候，忽略该属性
	private Map<String, Object> paraMap;

	public SimpleRespDTO() {
	}

	public Integer getPageNum() {
		return pageNum;
	}

	public void setPageNum(Integer pageNum) {
		this.pageNum = pageNum;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public Long getTotal() {
		return total;
	}

	public void setTotal(Long total) {
		this.total = total;
	}

	public String getRequestId() {
		return requestId;
	}

	public void setRequestId(String requestId) {
		this.requestId = requestId;
	}

	public String getReturnCode() {
		return returnCode;
	}

	public Map<String, Object> getParaMap() {
		if (this.paraMap == null) {
			this.paraMap = new HashMap<String, Object>();
		}
		return paraMap;
	}

	public void setParaMap(Map<String, Object> paraMap) {
		this.paraMap = paraMap;
	}

	public Map<String, Object> getData() {
		if (this.data == null) {
			this.data = new HashMap<String, Object>();
		}
		return data;
	}

	public void setData(Map<String, Object> data) {
		this.data = data;
	}

	@JSONField(serialize = false)
    public String getRespParameter(String key) {
        if (this.data != null) {
            return data.get(key) == null ? null : data.get(key).toString();
        }

        return null;
    }
	
	/**
	 * 向resp的map中加入数据
	 * 
	 * @param key
	 * @param value
	 */
	public void addParamToData(String key, Object value) {
		if (key != null) {
			if (this.data == null) {
				this.data = new HashMap<String, Object>();
			}
			this.data.put(key, value);
		}
	}

	/**
	 * 向resp的map中加入数据
	 * 
	 * @param map
	 */
	public void addParamsMapToData(Map<String, Object> map) {
		if (map != null) {
			if (this.data == null) {
				this.data = map;
			} else {
				this.data.putAll(map);
			}

		}
	}

	/**
	 * 如果返回码的模块已经定义了或者返回码为成功，调用该方法
	 * 
	 * @param returnCode
	 */
	public void setReturnCode(String returnCode) {
		this.returnCode = returnCode;
	}

	public String getReturnMsg() {
		return returnMsg;
	}

	public void setReturnMsg(String returnMsg) {
		this.returnMsg = returnMsg;
	}

	public void setSuccess() {
		this.returnCode = CommonCst.RESPONSE_OK;
	}


	@JSONField(serialize = false)
	public boolean isOk(){
		return CommonCst.RESPONSE_OK.equals(this.returnCode);
	}

}

